﻿namespace YK.Console.Business.DataDicts;

internal class CreateDataDictValidator : AbstractValidator<CreateDataDictRequest>
{
    public CreateDataDictValidator(IReadRepository<DataDictInfo> _repo)
    {
        RuleFor(x => x)
            .MustAsync(async (inst, ct) => !await _repo.SimpleAnyAsync(x => x.Code == inst.Code || x.Name == inst.Name, ct))
            .WithMessage(_ => "字典编码或字典名称重复");
    }
}


internal class UpdateDataDictValidator : AbstractValidator<UpdateDataDictRequest>
{
    public UpdateDataDictValidator(IReadRepository<DataDictInfo> _repo)
    {
        RuleFor(x => x)
            .MustAsync(async (inst, ct) => !await _repo.SimpleAnyAsync(x => (x.Code == inst.Code || x.Name == inst.Name) && x.Id != inst.Id, ct))
            .WithMessage(_ => "字典编码或字典名称重复");
    }
}